#!/bin/bash
set -e

CURRENT_DIR="$(cd "$(dirname "$0")"; pwd)"
ROOT_DIR="$(cd "${CURRENT_DIR}"; pwd)"
RPM_SOURCE_DIR="$HOME/rpmbuild/SOURCES"
RPM_SPEC_DIR="$HOME/rpmbuild/SPECS"

if [ ! -d $RPM_SOURCE_DIR ]; then
    mkdir -p $RPM_SOURCE_DIR
fi

if [ ! -d $RPM_SPEC_DIR ]; then
    mkdir -p $RPM_SPEC_DIR
fi

cargo clean
cd ..
tar -zcf huawei-ra.tar.gz huawei-ra
mv huawei-ra.tar.gz $RPM_SOURCE_DIR

cd huawei-ra
cargo vendor
tar -zcf vendor.tar.gz vendor
mv vendor.tar.gz $RPM_SOURCE_DIR

cp hra.spec $RPM_SPEC_DIR

rpmbuild -bb --clean $RPM_SPEC_DIR/hra.spec